﻿@model  DHQGHN.DAL.Common.DataPage<DHQGHN.PM2.Models.DHQG.NguoiDungModel>
@{
    var pagNar = ViewBag.Pagination as DHQGHN.DAL.Common.Pagination;
    var lstItem = Model.Data;
}
<link href="~/Content/index.css" rel="stylesheet" />
<table class="tbl">
    <thead>
        <tr>
            <th style="width:4%">STT</th>
            <th style="width:5%">Chọn</th>
            <th style="width:20%">Tài khoản</th>
            <th style="width:25%">Họ tên</th>
            <th style="width:10%">Điện thoại</th>
            <th style="width:25%">Đơn vị</th>
            <th style="width:10%">Trạng thái</th>
            <th style="width:8%">Thao tác</th>
        </tr>
    </thead>
    <tbody>
        @if (Model != null && Model.Data.Any())
        {
            for (int i = 0; i < lstItem.Count; i++)
            {
                <tr>
                    @if (@lstItem[i].DELETED == 0)
                    {
                        <td class="align-center">
                            <span>@(i + 1 + pagNar.CurrentPage * pagNar.PageSize)</span>
                        </td>
                        <td style="text-align:center">
                            <div id="checkboxUser">
                                <input type="checkbox" name="@lstItem[i].NGUOI_DUNG_ID" value="@lstItem[i].TAI_KHOAN" />
                            </div>
                        </td>
                        <td class="clsUserName hidden-480">
                            <span id="spnUserName" class="display-mode">
                                @lstItem[i].TAI_KHOAN
                            </span>
                        </td>
                        <td>
                            <div id="spnFullName" class="hidden-580">@lstItem[i].HO_VA_TEN</div>
                            <div class="display-580"><b>@lstItem[i].HO_VA_TEN</b></div>
                            @*<span class="display-480">Tài khoản: @lstItem[i].TAI_KHOAN</span>
                                <span class="display-480">Điện thoại: @lstItem[i].DIEN_THOAI</span>*@
                        </td>

                        <td class="clsUserName hidden-480">
                            <span id="spnUserName" class="display-mode">
                                @lstItem[i].DIEN_THOAI
                            </span>
                        </td>
                        <td class="clsUserName hidden-480">
                            <span id="spnUserName" class="display-mode">
                                @lstItem[i].TEN_DON_VI
                            </span>
                        </td>
                        <td style="text-align: center;color:green">Đang sử dụng</td>
                        <td style="text-align: center;">
                            <a title='Sửa thông tin người dùng' data-toggle='confirmation' href='javascript:void(0)'
                               class='user-edit' data-id='@lstItem[i].NGUOI_DUNG_ID'>
                                <div class='glyphicon glyphicon-edit'></div>
                            </a>
                        </td>
                        @*<td class="action">
                                <div style="text-align:center;">
                                    <div class="btn-group">
                                        <a href="#" data-toggle="dropdown" class="btn btn-lg" style="margin:0px; padding:0px;">
                                            <div class="label label-info">
                                                <i class="fa fa-th"></i>
                                            </div>
                                        </a>
                                        <ul class="dropdown-menu no-angle pull-right right">
                                            <li>
                                                <a onclick="nhomdonviEdit(@lstItem[i].NGUOI_DUNG_ID)" data-index="@lstItem[i].NGUOI_DUNG_ID" style="cursor:pointer;"> <i class="fa fa-pencil"></i> Cập nhật thông tin</a>
                                            </li>
                                            <li>
                                                <a onclick="actionDelete(@lstItem[i].NGUOI_DUNG_ID)" data-index="@lstItem[i].NGUOI_DUNG_ID" style="cursor:pointer;"> <i class="fa fa-trash-o"></i> Xóa thông tin</a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </td>*@
                    }
                    else
                    {
                        <td class="align-center">
                            <span>@(i + 1 + pagNar.CurrentPage * pagNar.PageSize)</span>
                        </td>
                        <td style="text-align:center"></td>
                        <td class="clsUserName hidden-480">
                            <span id="spnUserName" class="display-mode">
                                @lstItem[i].TAI_KHOAN
                            </span>
                        </td>
                        <td>
                            <div id="spnFullName" class="hidden-580">@lstItem[i].HO_VA_TEN</div>
                            <div class="display-580"><b>@lstItem[i].HO_VA_TEN</b></div>
                        </td>

                        <td class="clsUserName hidden-480">
                            <span id="spnUserName" class="display-mode">
                                @lstItem[i].DIEN_THOAI
                            </span>
                        </td>
                        <td class="clsUserName hidden-480">
                            <span id="spnUserName" class="display-mode">
                                @lstItem[i].TEN_DON_VI
                            </span>
                        </td>
                        <td style="text-align: center;color:red">Không sử dụng</td>
                        <td style="text-align: center;">
                            <a title='Đưa vào sử dụng' data-toggle='confirmation' href='javascript:void(0)'
                               class='re-active' data-id='@lstItem[i].NGUOI_DUNG_ID' data-user-name="@lstItem[i].TAI_KHOAN">
                                <div class='glyphicon glyphicon-play'></div>
                            </a>
                        </td>
                    }
                </tr>
            }
        }
        else
        {
            <tr>
                <td colspan="9"><p style="width: 100%; text-align:center;">Không tìm danh mục nào.</p></td>
            </tr>
        }
    </tbody>
    @if (Model != null && Model.Data.Any())
    {
        <tfoot>
            <tr>
                <td colspan="9" style="text-align:left;height:25px">
                    <button type="button" class="btn btn-danger" title="Xóa người dùng" id="btnDelete" style="height: 25px; margin-top: 5px; padding-top: 3px;">
                        Ngừng sử dụng
                    </button>
                </td>
            </tr>

            <tr>
                <td colspan="9">
                    @if (Model.Data.Any())
                    {
                        @Html.Partial("_PaginationView", pagNar)
                    }
                </td>
            </tr>
        </tfoot>
    }


</table>



<script type="text/javascript">
    $(function () {
        $('.clsSTT').css('text-align', 'center');
        var colsHeader = $('#gridContent th');
        //$(colsHeader[2]).addClass('hidden-480');
        //$(colsHeader[3]).addClass('hidden-580');
        //$(colsHeader[4]).addClass('hidden-780');
        //$(colsHeader[5]).css('text-align', 'center').css('width', '50px');
    });
</script>
@*</div>*@
<script>
    @functions{
            public string GetAntiForgeryToken()
            {
                string cookieToken, formToken;
                AntiForgery.GetTokens(null, out cookieToken, out formToken);
                return cookieToken + "," + formToken;
            }
        }
</script>
<script type="text/javascript">


    $(document).ready(function () {

        $('.user-edit').bind('click', function (event) {
            functionCreateOrUpdate($(this).attr('data-id'), "Cập nhật", "Cập nhật")
        });

        $('.country-active').bind('click', function (event) {
            activeCertification($(this).attr('data-id'))
        });

        $('#btnDelete').click(function () {
            var values = [];
            var userName = [];
            $('#checkboxUser input:checked').each(function () {
                values.push(this.name);
                userName.push(this.value);
            });
            if (values.length != 0) {
                var $self = $(this);
                comfirmDelete(messager.confirmUnuse, function () {
                    $.ajax("/NguoiDungAdmin/ActionDelete", {
                        type: "post",
                        contentType: "application/json",
                        //data: JSON.stringify({ listID: values }), // JSON data goes here
                        data: JSON.stringify({ id: values, userName: userName }),
                        dataType: "json",
                        headers: headers,
                        success: function (response) {
                            if (response.status == 200) {
                                OnCriteria(currentPageIndex);
                                window.notice(response.result, window.notice_success);
                            }
                            else {
                                window.notice(response.result, window.notice_error);
                            }
                        },
                        error: function (ex) {
                            alert(JSON.stringify(ex));
                        }
                    });
                }, null, "Thông báo");
            } else {
                warning(messager.selectRecord, "Thông báo");
            }
        });
    });

    function actionDelete(id) {

        var box = bootbox.dialog({
            title: "Xóa tài khoản",
            message: "Bạn có chắc chắn xóa tài khoản này không?",
            onEscape: function () {
                box.modal('hide');
            },
            buttons: {
                success: {
                    label: "<i class='fa fa-warning'></i> Xóa",
                    className: "btn btn-sm btn-danger", //btn-success
                    callback: function () {
                        //$("#divLoading").show();
                        $.ajax({
                            url: '/NguoiDungAdmin/ActionDelete',
                            headers: headers,
                            data: {
                                id: id
                            },
                            //dataType: 'json',
                            type: 'post',
                            success: function (response) {
                                if (response != null && response.status == 200) {
                                    Layout.toastr("", response.result);
                                    OnCriteria(0);
                                    result = true;
                                } else {
                                    Layout.toastr("", response.result);
                                }
                                //$("#divLoading").hide();
                            },
                            complete: function () {

                            },
                            error: function (ex) {
                                alert(JSON.stringify(ex));
                            }
                        });

                    }
                },
                danger: {
                    label: "<i class='fa fa-reply'></i> Hủy bỏ",
                    className: "btn btn-sm btn-default",//"btn-danger",
                    callback: function () {
                    }
                }
            }
        });
    }

    $('.re-active').bind('click', function (event) {
        $('.ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-dialog-buttons').show();
        $("body").on('click', function (e) {
            $(".ui-dialog .ui-dialog-titlebar-close").click();
            $('body').off('click');
        });
        $(".ui-dialog").on('click', function (e) {
            e.stopPropagation();
        });
        event.stopPropagation();
        var $self = $(this);
        comfirmDelete("Bạn có muốn đưa người dùng đã xóa vào sử dụng không ?", function () {
            $.ajax("/NguoiDungAdmin/Reactive", {
                type: "post",
                contentType: "application/json",
                data: JSON.stringify({ nguoiDungId: $self.attr('data-id'), taiKhoan: $self.attr('data-user-name') }), // JSON data goes here
                dataType: "json",
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                success: function (response) {
                    if (response.status == 200) {
                        OnCriteria(currentPageIndex);
                        window.notice(response.result, window.notice_success);
                    }
                    else {
                        window.notice(response.result, window.notice_error);
                    }
                },
            });
        }, null, "Đưa vào sử dụng");
    });

</script>
